<template>
    <div class="app-container">
      <el-form :model="csdfee" ref="p" size="small" :inline="true" v-show="showSearch" label-width="68px">
        <el-form-item label="社区ID" prop="deptId">
          <el-input v-model="csdfee.deptId" placeholder="请输入社区ID" clearable style="width: 240px"
            @keyup.enter.native="handleQuery" />
        </el-form-item>
        <el-form-item label="门牌号" prop="houseNum">
          <el-input v-model="csdfee.houseNum" placeholder="请输入门牌号" clearable style="width: 240px"
            @keyup.enter.native="handleQuery" />
        </el-form-item>
        <el-form-item label="费用类型" prop="feeType">
          <el-select v-model="csdfee.feeType" placeholder="请选择费用类型" clearable style="width: 240px">
            <el-option v-for="dict in dict.type.csd_fee_type" :key="dict.value" :label="dict.label"
              :value="dict.value" />
          </el-select>
        </el-form-item>
        <el-form-item label="包含项" prop="includeOptions">
          <el-input v-model="csdfee.includeOptions" placeholder="请输入包含项" clearable style="width: 240px"
            @keyup.enter.native="handleQuery" />
        </el-form-item>
        <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
      </el-form>
      <el-row :gutter="10" class="mb8">
        <el-col :span="1.5">
          <el-button type="primary" plain icon="el-icon-plus" size="mini" @click="handleAdd"
            v-hasPermi="['fee:fee:add']">新增</el-button>
        </el-col>
  
        <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
      </el-row>
  
      <el-table v-loading="loading" :data="fee">
        <el-table-column label="社区ID" align="center" prop="deptId" :show-overflow-tooltip="true" />
        <el-table-column label="门牌号" align="center" prop="houseNum" />
        <el-table-column label="费用类型" align="center" prop="feeType">
          <template slot-scope="scope">
            <dict-tag :options="dict.type.csd_fee_type" :value="scope.row.feeType" />
          </template>
        </el-table-column>
        <el-table-column label="包含项" align="center" prop="includeOptions" />
        <el-table-column label="单价" align="center" prop="price"  />
        <el-table-column label="开始日期" align="center" prop="startDate"/>
        <el-table-column label="结束日期" align="center" prop="endDate" />
        <el-table-column label="创建者" align="center" prop="createBy" width="100" />
        <el-table-column label="创建时间" align="center" prop="createTime" width="180">
          <template slot-scope="scope">
            <span>{{ parseTime(scope.row.createTime) }}</span>
          </template>
        </el-table-column>
        <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
          <template slot-scope="scope">
            <el-button size="mini" type="text" icon="el-icon-edit" @click="handleUpdate(scope.row)"
              v-hasPermi="['fee:fee:edit']">修改</el-button>
            <el-button size="mini" type="text" icon="el-icon-delete" @click="handleDelete(scope.row)"
              v-hasPermi="['fee:fee:remove']">删除</el-button>
          </template>
        </el-table-column>
      </el-table>
      <pagination v-show="total > 0" :total="total" :page.sync="csdfee.pageNum" :limit.sync="csdfee.pageSize"
        @pagination="getList" />
  
      <!-- 添加或修改参数配置对话框 -->
      <el-dialog :title="title" :visible.sync="dialogVisible" width="500px">
        <el-form ref="form" :model="form" :rules="rules" label-width="80px">
            <el-form-item label="社区ID" prop="deptId">
            <el-input v-model="form.deptId" placeholder="请输入社区ID" />
          </el-form-item>
          <el-form-item label="门牌号" prop="houseNum">
            <el-input v-model="form.houseNum" placeholder="请输入门牌号" />
          </el-form-item>
          <el-form-item label="费用类型" prop="feeType">
            <el-select v-model="form.feeType" placeholder="请选择费用类型">
              <el-option v-for="dict in dict.type.csd_fee_type" :key="dict.value" :label="dict.label"
                :value="dict.value"></el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="包含项" prop="includeOptions">
            <el-input v-model="form.includeOptions" />
          </el-form-item>
          <el-form-item label="单价" prop="price">
            <el-input v-model="form.price" />
          </el-form-item>
         
          <el-form-item label="开始日期"  prop="startDate">
            <el-date-picker v-model="form.startDate" :picker-options="pickerStartOptions" value-format="yyyy-MM-dd"   placeholder="选择开始日期" />
          </el-form-item>
          <el-form-item label="结束日期"  prop="endDate">
            <el-date-picker 
	v-model="form.endDate" 
	:picker-options="pickerEndOptions"
    value-format="yyyy-MM-dd" 
    placeholder="选择结束日期" />
         
</el-form-item>
       <el-form-item label="备注" prop="remark">
            <el-input v-model="form.remark" placeholder="请输入备注" />
          </el-form-item>
        </el-form>
        <div slot="footer" class="dialog-footer">
          <el-button type="primary" @click="submitForm">确 定</el-button>
          <el-button @click="cancel">取 消</el-button>
        </div>
      </el-dialog> 
  
    </div>
  </template>
  <script>
  import { selectFee,delFee,addFee,upFee,type} from "@/api/fee/fee";
  export default {
    name: "fee",
    dicts: ['csd_fee_type'],
    data() {    
      return {
        pickerStartOptions: {
         //禁用日期diabledDate
          disabledDate: (time) => {
              if (this.form.endDate) {
                  return time.getTime() > new Date(this.form.endDate).getTime(); 
              }          
          }
      },

     pickerEndOptions: {
          disabledDate: (time) => {
              if (this.form.startDate) {
                  return time.getTime() < new Date(this.form.startDate).getTime()
              }             
          }
      },

        //显示搜索条件
        showSearch: true,
        // 遮罩层
        loading: true,
        //总条数
        total: 0,
        isd:[],
        title:"",
        fee: [],
        dialogVisible: false,
        // 选中数组
        //查询参数
        csdfee: {
          pageNum: 1,
          pageSize: 10,
          deptId:undefined,
          houseNum: undefined,
          feeType: undefined,
          includeOptions: undefined,
        },
        form: {
        id: undefined,
        deptId:undefined,
        houseNum: undefined,
        feeType: undefined,
        includeOptions: undefined,
        price: undefined,
        startDate: undefined,
        endDate: undefined,
        remark:undefined
      },   
        rules: {
          deptId: [
          { required: true, message: "社区ID不能为空", trigger: "blur" }
        ],
          houseNum: [
          { required: true, message: "门牌号不能为空", trigger: "blur" }
        ], 
        feeType: [
          { required: true, message: "费用类型不能为空", trigger: "blur" }
        ],
        includeOptions: [
          { required: true, message: "包含项不能为空", trigger: "blur" }
        ],
        price: [
          { required: true, message: "单价不能为空", trigger: "blur" }
        ],
        startDate: [
          { required: true, message: "开始日期不能为空", trigger: "blur" },
        ],
        endDate: [
          { required: true, message: "结束日期不能为空", trigger: "blur" },
          

          ]  
        }  
      };
  
    },
    created() {
      this.getList();
    },
    methods: {

      //显示列表
      getList() {
        selectFee(this.csdfee).then(response => {
          this.fee = response.rows;
          this.total = response.total;
          this.loading = false;
        });
      },
      //删除
      handleDelete(row) {
      console.log(row)
      const id = row.id;
      this.$modal.confirm('是否确认删除为"' + id + '"的数据项？').then(function () {
        return delFee(id);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => { });
    },
    //搜索按钮操作
    handleQuery() {
      this.csdfee.pageNum = 1;
      this.getList();
    },
    //新增按钮操作
    handleAdd() {
      this.reset();
      this.dialogVisible = true;
    },
    // 取消按钮
    cancel() {
      this.dialogVisible = false;
      this.reset();
    },
    //重置按钮操作
    resetQuery() {
      this.csdfee = {
        pageNum: 1,
        pageSize: 10,
        deptId:undefined,
        houseNum: undefined,
        feeType: undefined,
        includeOptions: undefined,
        price: undefined,
        startDate: undefined,
        endDate: undefined,
      },
        this.resetForm("p");
        this.handleQuery();
    },
    submitForm: function () {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != undefined) {
            upFee(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.dialogVisible = false;
              this.getList();
            });
          } else {
            addFee(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.dialogVisible = false;
              this.getList();
            });
          }
        }
      });
    },
    reset() {
      this.form = {
        id: undefined,
        deptId:undefined,
        houseNum: undefined,
        feeType: undefined,
        includeOptions: undefined,
        price: undefined,
        startDate: undefined,
        endDate: undefined,
      };
      this.resetForm("form");
    },
    //修改 
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      type(id).then(response => {
        this.form = response.fee;
        this.dialogVisible = true;
        this.title = "修改";
      });
    },
    }
  };
  </script>
  <style scoped></style>


  